package cn.wes.waudiotool.file;

import android.util.Log;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class FindFile {
    private final static String TAG = "Find";
    private final String path="/sdcard";

    List<HashMap<String, Object>> listItem = new ArrayList<HashMap<String,Object>>();


    public void searchinit(){

        File[] files = new File(path).listFiles();
        searchAllFile(files);


    }

    //查找文件所有音频文件

    public void searchAllFile(File[] files){
        for (File file : files)
        {
            if (file.isDirectory())//若为目录则递归查找
            {
                searchAllFile(file.listFiles());
            }
            else if (file.isFile())
            {
                String path = file.getPath();
                if (path.endsWith(".mp3") || path.endsWith(".wav"))//查找指定扩展名的文件
                {
                    //do someth
                    HashMap<String,Object> map;
                    map = new HashMap<String,Object>();
                    map.put("name", path);
                    Log.i(TAG, "path :" + path );
                    listItem.add(map);
                }
            }
        }
    }

}
